import sys
sys.path.append("..")
from config.mysql_info import db, cursor
from ZongHeng import ZongHeng


class ZongHengMysql(ZongHeng):
    def save(self):
        for book in self.getBooks():
            self.appendTable(*list(book.values()))

    def appendTable(self, name, intro, img):
        cursor.execute(
            f"insert into zongheng values(null,'{name}','{intro}','{img}');")
        db.commit()


if __name__ == "__main__":
    ZongHengMysql(
        "http://book.zongheng.com/store/c0/c0/b0/u0/p1/v9/s1/t0/u0/i1/ALL.html").save()
